from PySide2.QtGui import QIcon

from boot import QLabel, Qt, QPixmap, QWidget, ToolTipFilter, Union, GlobalWidget


__all__ = ["QQ9WindowTitle"]


class QQ9WindowTitle(QLabel):

    def __init__(self,
                 parent: Union[QWidget, None] = None,
                 icon_path: str = "",
                 title: str = ""
                 ):
        super().__init__(parent=parent)

        # 基础设置
        self.setFixedSize(61, 45)
        self.setContentsMargins(0, 0, 0, 0)
        self.setAlignment(Qt.AlignCenter)
        self.move(0, 10)

        # 悬浮提示
        self.installEventFilter(ToolTipFilter(self, 100))
        self.setToolTip(self.tr(title))
        GlobalWidget.root.setWindowIcon(QIcon(icon_path))
        GlobalWidget.root.setWindowTitle(title)

        # 设置ICON
        self.set_icon(icon_path)

        #设置样式
        self._set_style_sheet()

    def _set_style_sheet(self):
        self.setStyleSheet(
            """
            QLabel {
                background-color: transparent;
            }
            """
        )

    def set_icon(self, icon_path: str):
        """
        设置图标
        :param icon_path: 图标地址
        :return:
        """
        pixmap = QPixmap(icon_path)
        scaled_pixmap = pixmap.scaled(32, 32, Qt.KeepAspectRatio, Qt.SmoothTransformation)
        self.setPixmap(scaled_pixmap)